<template>
  <div class="sidebar-wrapper">
    <Logo></Logo>
    <el-scrollbar class="scrollbar-wrapper">
      <el-menu
        class="menu-wrapper"
        background-color="var(--yy-sidebar-menu-bg-color)"
        text-color="var(--yy-sidebar-menu-text-color)"
        active-text-color="var(--yy-sidebar-menu-active-color)"
        :default-active="activeMenu"
        :collapse="props.isCollapse"
        :router="true"
      >
        <el-menu-item index="/dashboard">
          <el-icon><i-ep-setting /></el-icon>
          <template #title>首页</template>
        </el-menu-item>
        <MenuItem
          v-for="item in addRoutes"
          :key="item.path"
          :item="item"
          :is-collapse="props.isCollapse"
          :is-first-level="true"
          :base-path="item.path"
        >
        </MenuItem>
      </el-menu>
    </el-scrollbar>
  </div>
</template>

<script setup lang="ts">
import MenuItem from './MenuItem.vue';
import { useActiveMenu } from './useMenu';
defineComponent({ name: 'Sidebar' });

const props = withDefaults(
  defineProps<{
    isCollapse?: boolean;
    isTop?: boolean;
    isFirstLevel?: boolean;
    basePath?: string;
  }>(),
  {
    isCollapse: false,
    isTop: false,
    isFirstLevel: true,
    basePath: ''
  }
);

const { addRoutes } = usePermissionStore();

const { activeMenu } = useActiveMenu();
</script>

<style lang="scss" scoped>
.sidebar-wrapper {
  height: inherit;
  .logo {
    height: var(--yy-navbar-height);
    background-color: var(--yy-sidebar-menu-bg-color);
  }
  .scrollbar-wrapper {
    height: calc(100% - var(--yy-navbar-height));
    background-color: var(--yy-sidebar-menu-bg-color);
    .menu-wrapper {
      height: inherit;

      &:not(.el-menu--collapse) {
        width: var(--yy-sidebar-width);
      }
      &.el-menu--collapse {
        width: var(--yy-sidebar-hide-width);
      }
    }
  }
}
</style>
